﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess
{
    class DataProvider
    {
        public SqlConnection cn;
        public SqlCommand cm;
        public SqlDataAdapter da;
        public string connectString = "Data Source=.;Initial Catalog=Airplane;Integrated Security=True";
        public void KetNoi()
        {
            cn = new SqlConnection(connectString);
            cn.Open();
        }
        public void NgatKetNoi()
        {
            cn.Close();
        }
        public void ExecuteNonQuery(string sql)
        {
            cm = new SqlCommand(sql,cn);
            cm.ExecuteNonQuery();
        }
        public DataTable ExcuteQuery(string sql)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            da = new SqlDataAdapter(sql,cn);
            da.Fill(ds);
            return ds.Tables[0];
            
        }
        public object executeScalar(string sql)
        {
            cm = new SqlCommand(sql, cn);
            return cm.ExecuteScalar();
        }

    }
}
